package com.wondertek.service.mapper.business;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.service.dto.business.req.AccessoryPageReq;
import com.wondertek.service.dto.business.res.AccessoryPageRes;
import com.wondertek.service.entity.business.AccessoryPo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AccessoryMapper extends BaseMapper<AccessoryPo> {


    @Select("<script> select a.id,a.accessory_code,a.accessory_name,a.room_id," +
            "(select room_name from room r where r.id = a.room_id) room_name, " +
            "a.type_detail_id,a.sn_code,a.sk_code,a.accessory_type,c.sn_code deviceSn,a.status,a.arming_enable armingEnable from accessory  a " +
            "left join room b on b.id=a.room_id " +
            "left join device c on c.id=b.device_id " +
            "where a.is_delete = 0 " +
            "<if test='req.roomId != null and req.roomId != \"\"'> " +
            " and b.id = #{req.roomId} </if> " +
            "<if test='req.accessoryName != null and req.accessoryName != \"\"'> " +
            " and a.accessory_name like concat('%',#{req.accessoryName},'%') </if> " +
            "<if test='req.deviceId != null and req.deviceId != \"\"'> " +
            " and c.id = #{req.deviceId}  </if> " +
            "</script>")
    Page<AccessoryPageRes> webPage(AccessoryPageReq req, Page page);

    /*
     * 根据sn查询已删除的配件
     * */
    List<AccessoryPo> selectBysql(@Param("code")String code);

}
